﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Live;
using Microsoft.Live.Controls;
using Common.Library;
using System.Threading.Tasks;
namespace SyncStories
{
    public partial class SyncButton : UserControl
    {
        public static LiveConnectClient client;
        public static LiveAuthClient authclient;
        public static LiveConnectSession session = default(LiveConnectSession);
        public static string FolderID = string.Empty;
        public static string Folderid = string.Empty;
        public SyncButton()
        {
            InitializeComponent();

        }

        private void btnSignin_SessionChanged(object sender, Microsoft.Live.Controls.LiveConnectSessionChangedEventArgs e)
        {


            if (e.Status == LiveConnectSessionStatus.Connected)
            {

                client = new LiveConnectClient(e.Session);
                if (e.Session != null)
                {
                    session = e.Session;
                    AppSettings.SkyDriveLogin = true;
                }
                else
                {
                    AppSettings.SkyDriveLogin = false;
                }


            }

        }

        public static async Task login()
        {
            try
            {
                string[] scopes = new string[2];
                scopes[0] = "wl.offline_access";
                scopes[1] = "wl.skydrive_update";
                authclient = new LiveAuthClient("00000000400E9AD0");
              
              LiveLoginResult result=await authclient.InitializeAsync(scopes);
              if (result.Status == LiveConnectSessionStatus.Connected)
                {
                    session = result.Session;
                    AppSettings.SkyDriveLogin = true;
                }
                else
                {
                    AppSettings.SkyDriveLogin = false;
                }

            
            }
            catch (Exception ex)
            {

            }
        }

       

      


    }
}
